package com.github.byakkili.bim.autoconfigure;

import com.github.byakkili.bim.core.BimNettyServer;
import lombok.RequiredArgsConstructor;
import org.springframework.context.SmartLifecycle;

/**
 * @author Guannian Li
 */
@RequiredArgsConstructor
public class BimServerStartStopLifecycle implements SmartLifecycle {

    private final BimNettyServer bimNettyServer;

    private volatile boolean running = false;

    @Override
    public void start() {
        bimNettyServer.start();
        running = true;
    }

    @Override
    public void stop() {
        bimNettyServer.stop();
        running = false;
    }

    @Override
    public boolean isRunning() {
        return running;
    }

    @Override
    public int getPhase() {
        return Integer.MAX_VALUE - 1;
    }
}
